namespace CSharpPro._1030;

public class Demo
{
    private Son son = new Son();
    private Father father = new Father();
    //son2调用的是son类中的方法
    private Father son2 = new Son();
    private Father child = new Child();
    private Father student = new Student();
    
    //创建字段
    private int id;
    private string name;
    
    //创建属性，在C#中只有包含get，set方法的字段才能成为属性,否则称为字段
    public int Id
    {
        get => id;
        set => id = value;
    }
    
    public string Name
    {
        get => name;
        set => name = value ?? throw new ArgumentNullException(nameof(value));
    }
    
    public void Test()
    {
        father.Print1();
        father.Print2();
        son.Print1();
        son.Print2();
        //在没被重写的情况下，会使用father类中的方法，如果在子类中被重写，则使用子类中重写之后的方法
        son2.Print1();
        son2.Print2();
    }

    /*子类会继承父类的属性，并调用父类的属性，但子类自己与父类同名的属性会被埋没
     如果用Father son=new Son()去实例化一个对象的话，那么这个对象只能调到父类的属性和仅在父类中声明的（非重写的）方法
     但如果方法被重写了则调用子类重写的方法*/
    public void Test2()
    {
        //调用类中的属性，查看属性的值是否能被继承,如果被继承如何调用，没继承，如何处理
        Console.WriteLine("father:"+father);
        Console.WriteLine("son:"+son);
        Console.WriteLine("son2:"+son2);
        Console.WriteLine("father.Name:" + father.Name);
        Console.WriteLine("father.NickName:"+father.NickName);
        Console.WriteLine("son.Name:" + son.Name1);
        Console.WriteLine("son.NickName:"+son.Realname);
        Console.WriteLine("son2.Name:" + son2.Name);
        Console.WriteLine("son2.NickName:" + son2.NickName);
    }

    public void Test3()
    {
        //测试销毁与析构的次序
        father.Deconstruct();
        son.Deconstruct();
        student.Deconstruct();
    }

    public void Test4()
    {
        //测试重构方法
        father.Print2();
        son.Print2();
        student.Print2();
        child.Print2();
    }
}